package com.usian.common.exception;

import com.usian.model.common.dtos.ResponseResult;

import com.usian.model.common.enums.AppHttpCodeEnum;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Log4j2
public class ExceptionCatch {

    @ExceptionHandler(Exception.class)
    @ResponseBody

    public ResponseResult catchException(Exception e){
        e.printStackTrace();
        // 记录日志
        log.error("服务器报错，报错信息如下:{}",e.getMessage());
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

}
